<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,user-scalable=no, initial-scale=1">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <title>我的签约服务</title>
    <%- include('./_global/baseLibs') %>
    <link rel="stylesheet"  href="/static/css/mycontract.css" />
</head>
<body>
<section class="page-wrap my-sign-service">
    <header class="header-box grey fixed">
        <div class="header-content">
            <div class="left-tool">
                <a class="back" href="javascript:void(0);"><i class="iconfont icon-back"></i></a>
            </div>
            <div class="title">我的签约服务</div>
        </div>
    </header>

    <div class="qy-list-box">
        <ul id="qy-ul">

        </ul>
        <div class="tj-btn-box">
            <a class="qyxq">查看签约协议</a>
        </div>
    </div>
</section>

<script>




    var page_wdqyfw = (function($, page_wdqyfw) {
        var qydm = "";
        var fwbids = [];
        var qyzt = $.QuickUrlUtils.getRequest("qyzt");//07表示，医生端已审核通过，但是用户还没有签名确认

        //加载数据
        function initData() {
            /**获取签约信息*/
            var qyxx = StoreCache.getCache("QYFW_QYLS_QYXX");
            qydm = qyxx["qyxxid"];
            if (!StringUtils.isEmpty(qydm)) {
                var qyxx = {qyxxid: qydm};
                /**查询服务信息*/
                $.QuickRemote.AjaxJson({
                    funcName:"/api/gzd/qyfw/queryQyfwByPageToJkcs",
                    params:qyxx,
                    callback:function (result) {
                        var ds = eval(result.row);
                        page_wdqyfw.queryFwxxBack(ds);
                        page_wdqyfw.clearPjbut(result.fwpj);//修改已经评价过的服务的“去评价”按钮
                    },
                });
            }
        }

        function queryFwxxBack(ds) {
            $(ds).each(function (index, item) {
                page_wdqyfw.setData(item);
            });
            fwbids = fwbids.join("|");
            page_wdqyfw.initView();
        }

        //修改已经评价过的服务的“去评价”按钮
        function clearPjbut(fwpj) {
            $.each(fwpj, function (i, item) {
                var a = $("a.pj-btn[fpfwid=" + item.wcfwdm + "]");
                a.unbind("click");
                a.html("已评价");
            });
        }

        //加载li
        function setData(ds) {
            page_wdqyfw.addfwb(ds);
            page_wdqyfw.addfwx(ds);
        }

        //添加服务包
        function addfwb(ds) {
            var ul = $("#qy-ul");
            var QYFW_QYLS_QYXX = StoreCache.getCache("QYFW_QYLS_QYXX");
            if ($(ul).find("li[id='" + ds.fwbid + "']").length == 0) {
                fwbids.push(ds.fwbid);
                var li = $("<li>").attr({id: ds.fwbid});
                var divOut = $("<div>").addClass("out-box");
                var icon = $("<i>").addClass("pencil-icon");
                var span = $("<span>").html(ds.fwbmc + "：" + QYFW_QYLS_QYXX["tdmc"]);
                var spanTime = $("<span>").addClass("date").html(ds.cjsj);
                var down = $("<i>").addClass("icon-down");
                divOut.append(icon).append(span).append(spanTime).append(down);
                li.append(divOut);
                var bigDiv = $("<div>").addClass("content-list-box");
                var fwxUl = $("<ul>").addClass("fwx");
                bigDiv.append(fwxUl);
                li.append(bigDiv);
                ul.append(li);
            }
        }

        //添加服务项
        function addfwx(ds) {
            var fwbUl = $("#qy-ul").find("li[id='" + ds.fwbid + "']");
            var ul = $(fwbUl).find(".fwx");
            var li = ul.find("li[fwid='"+ds.fwid+"']");
            if(li.length!=0)//已经做过的服务项，不需要重复添加
                return;
            li = $("<li>").attr("fwid",ds.fwid);

            var i = $("<i>").addClass("qy-icon");
            var div = $("<div>").addClass("text-box");
            var textspan = $("<span>").addClass("blue-text").html(ds.fwmc);
            var spannr = $("<span>").html("服务内容：" + ds.fwnr);
            var spansj = $("<span>").html("上次时间：" + ds.scfwsj.substr(0,10));
            var spanys = $("<span>").html("医生：" + ds.fwysxmys);
            div.append(textspan).append(spannr).append(spansj).append(spanys);
            li.append(i).append(div);
            //如果没有最后一次的服务信息，表示没有服务历史
//        if (ds.SCFWSJ) {

            if(qyzt == "07"){
                123	}
            else if (ds.scfwsj) {
                var als = $("<a>").addClass("cklc-text").attr({href: "javascript:void(0);"}).html("查看历次");
                var apj = $("<a>").addClass("pj-btn").attr({href: "javascript:void(0);"}).html("去评价");
                apj.attr("FPFWID", ds.fpfwid);
                $(apj).on("click", function () {
                    StoreCache.setCache("QYFW_DPJFWXX", {
                        FWMC: ds.fwmc,
                        fwnr: ds.fwnr,
                        ysxm: ds.fwys,
                        wcfwsj: ds.scfwsj,
                        wcfwdm: ds.fpfwid
                    });
//                $.QuickUrlUtils.redirectJSBridge({url: "/html/signService/fwpj.html", title: "服务评价"});
                    $.QuickUrlUtils.redirectJSBridge({type:"qyfw",url:"fwpj.html", title: "服务评价"});
                });
                $(als).on("click", function () {
                    StoreCache.setCache("QYFW_FWXX", ds);
                    StoreCache.setCache("QYFW_DPJFWXX_FWMC", ds.fwmc);
//                $.QuickUrlUtils.redirectJSBridge({url: "/html/signService/lcfwpj.html", title: "历次服务"});
                    $.QuickUrlUtils.redirectJSBridge({type:"qyfw",url:"lcfwpj.html", title: "历次服务"});
                });
                li.append(als)
                // .append(apj)
                ;
            } else {
                var als = $("<a>").addClass("cklc-text").attr({href: "javascript:void(0);"}).html("暂无服务");
                li.append(als);
            }
            ul.append(li);

        }

        function initView() {
            /**查看服务协议*/
            $(".qyxq").on("click", function() {
                // StoreCache.setCache("isSelectFwxy", validate());
                var action = qyzt=="07"?"QYXYNR":"QYXY";
                $.QuickUrlUtils.redirectJSBridge({type:"qyfw",url:"/html/gzd/signService/yqyxq.html?action="+action+"&qyxxid="+qydm+"&fwbids="+fwbids,title:"服务协议详情"});
            });
            $(".out-box").on('click', function () {
                var liElem = $(this).parent();
                liElem.siblings().removeClass('active');
                var selectElem = liElem.find('.content-list-box');
                if (selectElem.length < 1) {
                    return
                }
                if (liElem.hasClass('active')) {
                    liElem.removeClass('active')
                } else {
                    liElem.addClass('active');
                }
            });
            $("#qy-ul").children('li').find(".content-list-box").find("li").click(function () {
                $(this).addClass('active').siblings().removeClass('active');
                var liElem = $(this).parent();
                //liElem.find('.input-select').val(this.innerText);
                liElem.removeClass('active')
            });
            $(".out-box:first").trigger("click");
        }

        var cfg_def = {
            initData: initData,
            queryFwxxBack: queryFwxxBack,
            clearPjbut: clearPjbut,
            setData: setData,
            addfwb: addfwb,
            addfwx: addfwx,
            initView: initView,
        }

        page_wdqyfw.init = function(cfg){
            $.extend(page_wdqyfw, cfg_def, cfg);
            page_wdqyfw.initData();

        }

        return page_wdqyfw;
    })(jQuery, {});
    

</script>
</body>
</html>